var form;
var $;
var table
var layer;
layui.use(['form','jquery','table','layer'],function() {
    form = layui.form;
    $ = layui.$;
    table = layui.table;
    layer = layui.layer;
});
var user = JSON.parse(localStorage.getItem('user'));
//添加编辑的操作日志
$.ajax({
    url:'/Product/addProductOperationRecord',
    dataType:'json',
    data:{
        "logType":1,"type":4,"userId":user.userId,
        "remark":"编辑反馈日志"
    }
});
var id = $('#proId',window.parent.document).val();
$('input[name = productId]').val(id);
var user = JSON.parse(localStorage.getItem('user'));
var originalpriceProduct;
$.ajax({
    url:'/Product/queryProduct',
    dataType:'json',
    data:{"productId":id},
    async: false,
    success:function (data) {
        data = data.data;
        originalpriceProduct = data[0].originalpriceProduct;
        $('input[name = productCode]').val(data[0].productCode);
        $('input[name = productName]').val(data[0].productName);
        $('input[name = currentpriceProduct]').val("￥"+data[0].currentpriceProduct);
        $('#productLabel').val("  "+data[0].productLabel);
        $('#productDescription').val("  "+data[0].productDescription);
        $("#proTitle").val(data[0].productSate);
        layui.form.render("select");
    }
});

//取消
function cancel(){
    var layer = parent.layer;
    layer.close(layer.index);
}
//确定修改

function determine(){
    var product;
    if(originalpriceProduct == $('input[name = currentpriceProduct]').val().substr(1)){
        product ={
            productId:$('input[name = productId]').val(),
            productCode:$('input[name = productCode]').val(),
            productName:$('input[name = productName]').val(),
            productLabel:$('#productLabel').val(),
            productDescription:$('#productDescription').val(),
            productSate:$('#proTitle').val()
        }
    }else{
        product ={
            originalpriceProduct:originalpriceProduct,
            productId:$('input[name = productId]').val(),
            productCode:$('input[name = productCode]').val(),
            productName:$('input[name = productName]').val(),
            currentpriceProduct:$('input[name = currentpriceProduct]').val().substr(1),
            productLabel:$('#productLabel').val(),
            productDescription:$('#productDescription').val(),
            productSate:$('#proTitle').val()
        }
        $.ajax({
            url:'/Product/addProductJournal',
            dataType:'json',
            data:{
                "dictSort":product.productCode,"dictLabel":product.productName,"dictValue":product.originalpriceProduct,
                "listClass":product.currentpriceProduct,"createBy":user.userId,"parentId":product.productId
            },
            success:function (data) {
                $.ajax({
                    url:'/Product/updateProduct',
                    data:product,
                    dataType:'json',
                    success:function (data) {
                        if(data.data){
                            var layer = parent.layer;
                            layer.close(layer.index);
                        }else{
                            layer.msg("修改失败");
                        }
                    }
                });
            }
        });
    }

}